4 func resize(by scale: CGFloat) -> CGImage? {
5 let width = Int(CGFloat(self.width) / scale)
6 let height = Int(CGFloat(self.height) / scale)
8 let bitsPerComponent = self.bitsPerComponent
9 let colorSpace = self.colorSpace ?? CGColorSpace(name: CGColorSpace.sRGB)!
10 let bitmapInfo = self.bitmapInfo.rawValue
12 guard let context = CGContext(data: nil, width: width, height: height, bitsPerComponent: bitsPerComponent, bytesPerRow: 0, space: colorSpace, bitmapInfo: bitmapInfo) else {
16 context.interpolationQuality = .high
17 context.draw(self, in: CGRect(x: 0, y: 0, width: width, height: height))
19 return context.makeImage()